|
|
|
|
|
|
|
As a Visual Basic programmer, you don't need to worry about these issues; they are well hidden from you. But understanding them becomes absolutely critical for advanced API and DLL calls. |
|
|
|
|
|
|
|
|
Figure T2-2:
Organization of memory in a 32-bit system with
4.2GB of memory |
|
|
|
|
|
|
|
|
What's this? You don't have 4.2 gigabytes of memory on your system? I confess, neither do I (though I do have that much disk space). |
|
|
|
|
|
|
|
|
Now, you may know that your system has only 16MB or 64MB of memory. And you may also know that this memory is shared among all the applications running on your system and the operating system itself. |
|
|
|
|
|
|
|
|
I want you to forget about that. |
|
|
|
|
|
|
|
|
From now on, all you need to know is that each one of your applications has a full 32-bit address space (4.2 GB) available all to itself. True, some of that area is reserved for the operating system, and you will rarely allocate memory from this space yourself. Also, most of that memory space does not have any real memory associated with itif you tried accessing those addresses, you would get a memory exception. The important thing is that, as far as your application is concerned, it has the entire system memory available for itself. This leads to some interesting situations, especially for those used to programming on 16-bit systems. It means that it is notoriously difficult to share memory on Win32 systems. (You can find out more about this subject in Chapter 14 of my book Dan Appleman's Visual Basic Programmer's Guide to the Win32 API.) |
|
|
|
|
|
|
|
|
We started this tutorial with some code that stored the number 5 using different types of variables. So, exactly how are those values stored in memory? The Memory.vbp project (on the CD that comes with this book) lets you look inside the individual bytes for each variable to see what it contains. The variables are defined at the form level and set to 5 in the form's Load event. The |
|
|
|
|
|